/*************************************************************************
 * File Name:    B.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Thu 17 Oct 2013 06:28:09 PM CST
 * 
 * Description:  http://codeforces.com/contest/356/problem/B
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iomanip>

using namespace std;

#define ALPHA_NUM 26
#define MAXN 1000010

int cnt[MAXN][ALPHA_NUM];

int
main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);
    long long n, m, ans;
    int d;
    string a, b;

    while (cin >> n >> m) {
        cin >> a >> b;
        d = __gcd(a.size(), b.size());
        memset(cnt, 0, sizeof(cnt));

        for (size_t i = 0; i < a.size(); ++i) {
            ++cnt[i % d][a[i] - 'a'];
        }
        ans = 0;
        for (size_t i = 0; i < b.size(); ++i) {
            ans += cnt[i % d][b[i] - 'a'];
        }
        ans *= n * d / b.size();
        cout << n * a.size() - ans << endl;
    }
    return 0;
}
